<?php
include "header.inc";
?>
<ul>
    <li>After Information Sessions:
        <?php table(array(), array()); ?>
    </li>
    <li>After Written Exams:
        <ul>
            <?php if (isset($_GET["attendees"]) && $_GET['attendees'] == "view_attendees") {
 ?>
            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php">Attendees:</a>
                <?php table(array("LEFT JOIN applicant_more_info ON applicant_more_info.applicant_id=applicant.applicant_id"), array("applicant_more_info.applicant_more_info_attendee_exam_status=1")); ?>

                <ul>
                    <?php if (isset($_GET["eligibles"]) && $_GET['eligibles'] == "view_eligibles") {?>
                        <li>
                            <a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?attendees=view_attendees">Eligibles</a>
                        <?php
                        $where = "";
                        $joins = array();
                        for ($i = 0; $i < count($programs); $i++) {
                            $p = $programs[$i];
                            array_push($joins, "LEFT JOIN applicant_eligibility AS ae" . $i . " ON (ae" . $i . ".applicant_id=applicant.applicant_id AND ae" . $i . ".program_id=" . $p["program_id"] . ")");
                            if ($where <> "")
                                $where .= " OR ";
                            $where .= "ae" . $i . ".eligible=1";
                        }
                        table($joins, array($where));
                        ?>
                        <ul>
                            <?php
                            $previous = array();
                            foreach ($programs as $p) {
                                echo "<li>Eligibles for " . $p["program_name"];
                                $joins = array("LEFT JOIN applicant_eligibility AS ae ON (ae.applicant_id=applicant.applicant_id AND ae.program_id=" . $p["program_id"] . ")");
                                $where = array("ae.eligible=1");
                                for ($i = 0; $i < count($previous); $i++) {
                                    array_push($joins, "LEFT JOIN applicant_eligibility AS ae" . $i . " ON (ae" . $i . ".applicant_id=applicant.applicant_id AND ae" . $i . ".program_id=" . $previous[$i]["program_id"] . ")");
                                    array_push($where, "ae" . $i . ".eligible=0");
                                }
                                table($joins, $where);
                                echo "</li>";
                                array_push($previous, $p);
                            }
                            ?>
                        </ul>
                    </li>
                    <?php } else {
 ?>
                            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?attendees=view_attendees&eligibles=view_eligibles">Eligibles</a></li>
<?php } ?>
                        <li><a href='eligibility.php'>More details on eligibility rules and exam results</a></li>
                    </ul>
                </li>

            <?php } else { ?>
            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?attendees=view_attendees">Attendees</a></li>
            <?php } ?>

            <?php if (isset($_GET["absents"]) && $_GET['absents'] == "view_absents") {
 ?>
                            <li>
                                <a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php">Absents:</a>
                <?php table(array("LEFT JOIN applicant_more_info ON applicant_more_info.applicant_id=applicant.applicant_id"), array("applicant_more_info.applicant_more_info_attendee_exam_status=2")); ?></li>
            <?php } else { ?>
                            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?absents=view_absents">Absents</a></li>
            <?php } ?>
            <?php if (isset($_GET["partially_attend"]) && $_GET['partially_attend'] == "view_partially_attend") {
 ?>
                            <li>
                                <a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php">Partially attend:</a>
                                <?php table(array("LEFT JOIN applicant_more_info ON applicant_more_info.applicant_id=applicant.applicant_id"), array("applicant_more_info.applicant_more_info_attendee_exam_status=3")); ?></li>
<?php } else { ?>
                            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?action=AW_Exam&partially_attend=view_partially_attend">Partially attend</a></li>
            <?php } ?>
            <?php if (isset($_GET["cheaters"]) && $_GET['cheaters'] == "view_cheaters") {
 ?>
                            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php">Cheaters:</a>
                                <?php table(array("LEFT JOIN applicant_more_info ON applicant_more_info.applicant_id=applicant.applicant_id"), array("applicant_more_info.applicant_more_info_attendee_exam_status=4")); ?></li>
<?php } else { ?>
                            <li><a href=" <?php echo $_SESSION["root_url"] ?>/stats/general.php?action=AW_Exam&cheaters=view_cheaters">Cheaters</a></li>
<?php } ?>
                    </ul>
                </li>

            </ul>
<?php
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbOk = $result[0]["COUNT(*)"];
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbTotal = $result[0]["COUNT(*)"];
//
//echo "Current status: ".$nbOk."/".$nbTotal." applicants still in the process<br/>";
//echo "Including:<br/>";
//flush();
//
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE ngo_id IS NOT NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbNGO = $result[0]["COUNT(*)"];
//echo " - ".$nbNGO." from NGOs (".percent($nbNGO,$nbOk).")<br/>";
//flush();
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND ngo_id IS NOT NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbMales = $result[0]["COUNT(*)"];
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND ngo_id IS NOT NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbFemales = $result[0]["COUNT(*)"];
//echo " &nbsp; - ".$nbMales." males (".percent($nbMales,$nbNGO).")<br/>";
//echo " &nbsp; - ".$nbFemales." females (".percent($nbFemales,$nbNGO).")<br/>";
//flush();
//
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbMales = $result[0]["COUNT(*)"];
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbFemales = $result[0]["COUNT(*)"];
//echo " - ".$nbMales." males (".percent($nbMales,$nbOk).")<br/>";
//echo " - ".$nbFemales." females (".percent($nbFemales,$nbOk).")<br/>";
//flush();
//
//echo "<br/><h1>Excluded from the process</h1><br/>";
//echo "<table border=1 style='border-collapse:collapse'>";
//echo "<tr><th>Reason</th><th>Total</th><th colspan=2>Males</th><th colspan=2>Females</th></tr>";
//$list = DataBase::query("SELECT DISTINCT excluded_reason FROM applicant WHERE excluded=1 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//if ($list <> false)
//foreach ($list as $r) {
//	$reason = $r["excluded_reason"];
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND excluded_reason='".mysql_escape_string($reason)."' AND excluded=1 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbMales = $result[0]["COUNT(*)"];
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND excluded_reason='".mysql_escape_string($reason)."' AND excluded=1 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbFemales = $result[0]["COUNT(*)"];
//	echo "<tr><td>".$reason."</td><td align=center>".($nbMales+$nbFemales)."</td><td align=center>".$nbMales."</td><td align=center>".percent($nbMales,$nbMales+$nbFemales)."</td><td align=center>".$nbFemales."</td><td align=center>".percent($nbFemales,$nbMales+$nbFemales)."</td></tr>";
//	flush();
//}
//echo "</table>";
//
//echo "<br/><h1>Overview per NGO</h1><br/>";
//echo "<table border=1 style='border-collapse:collapse'>";
//echo "<tr><th>NGO</th><th>Total</th><th colspan=2>Males</th><th colspan=2>Females</th></tr>";
//flush();
//$list = DataBase::select("ngo",null,null);
//foreach ($list as $ngo) {
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND ngo_id=".$ngo["ngo_id"]." AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbMales = $result[0]["COUNT(*)"];
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND ngo_id=".$ngo["ngo_id"]." AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbFemales = $result[0]["COUNT(*)"];
//	echo "<tr><td>".$ngo["ngo_name"]."</td><td align=center>".($nbMales+$nbFemales)."</td><td align=center>".$nbMales."</td><td align=center>".percent($nbMales,$nbMales+$nbFemales)."</td><td align=center>".$nbFemales."</td><td align=center>".percent($nbFemales,$nbMales+$nbFemales)."</td></tr>";
//	flush();
//}
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND ngo_id IS NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbMales = $result[0]["COUNT(*)"];
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND ngo_id IS NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbFemales = $result[0]["COUNT(*)"];
//echo "<tr><td><b><i>No NGO</i></b></td><td align=center>".($nbMales+$nbFemales)."</td><td align=center>".$nbMales."</td><td align=center>".percent($nbMales,$nbMales+$nbFemales)."</td><td align=center>".$nbFemales."</td><td align=center>".percent($nbFemales,$nbMales+$nbFemales)."</td></tr>";
//echo "</table>";
//
//echo "<br/><h1>Overview per High School</h1><br/>";
//echo "<table border=1 style='border-collapse:collapse'>";
//echo "<tr><th>High School</th><th>Total</th><th colspan=2>Males</th><th colspan=2>Females</th></tr>";
//flush();
//$list = DataBase::select("high_school",null,null);
//foreach ($list as $hs) {
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND high_school_id=".$hs["high_school_id"]." AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbMales = $result[0]["COUNT(*)"];
//	$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND high_school_id=".$hs["high_school_id"]." AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//	$nbFemales = $result[0]["COUNT(*)"];
//	echo "<tr><td>".$hs["high_school_name"]."</td><td align=center>".($nbMales+$nbFemales)."</td><td align=center>".$nbMales."</td><td align=center>".percent($nbMales,$nbMales+$nbFemales)."</td><td align=center>".$nbFemales."</td><td align=center>".percent($nbFemales,$nbMales+$nbFemales)."</td></tr>";
//	flush();
//}
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='M' AND high_school_id IS NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbMales = $result[0]["COUNT(*)"];
//$result = DataBase::query("SELECT COUNT(*) FROM applicant WHERE sex='F' AND high_school_id IS NULL AND excluded=0 AND selection_campaign_id=".$_SESSION["campaign_id"]);
//$nbFemales = $result[0]["COUNT(*)"];
//echo "<tr><td><b><i>No High School</i></b></td><td align=center>".($nbMales+$nbFemales)."</td><td align=center>".$nbMales."</td><td align=center>".percent($nbMales,$nbMales+$nbFemales)."</td><td align=center>".$nbFemales."</td><td align=center>".percent($nbFemales,$nbMales+$nbFemales)."</td></tr>";
//echo "</table>";
//
//flush();
?>